package com.yupi.yuapiclientsdk.client;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.yupi.yuapiclientsdk.model.User;
import com.yupi.yuapiclientsdk.utils.SignUtils;

import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lkc
 * @version 1.0
 * 调用第三方接口的api
 */
public class YuApiClient {

    protected String accessKey;

    protected String secretKey;

    //上线记得修改为线上地址，提供此SDK给他人下载导入使用
    protected static final String GATEWAY_HOST = "http://localhost:8090";//gateway地址

    public YuApiClient() {
    }

    public YuApiClient(String accessKey, String secretKey) {
        this.accessKey = accessKey;
        this.secretKey = secretKey;
    }

    Map<String,String> getHeaderMap(String body) {
        Map<String,String> hashMap = new HashMap<>();
        hashMap.put("accessKey",accessKey);
//        hashMap.put("secretKey",secretKey); 密钥不能当做请求发送给后端
        hashMap.put("nonce", RandomUtil.randomNumbers(4));
        hashMap.put("body",body);
        hashMap.put("timestamp",String.valueOf(System.currentTimeMillis()/1000));
        hashMap.put("sign", SignUtils.getSign(body,secretKey));
        return hashMap;
    }
}
